<template>
  <div>
    <tableComponents :pagination="{currentPage,pageSize,total:list.all_num}" @handleCurrentChange="handleCurrentChange"
        @handleSizeChange="handleSizeChange" :isHaveExport="false" @toAdd="add_data" :searchData="userSearchData" @sendUserSearch="receive_search">
      <template v-slot:table>
        <el-table ref="multipleTable" :data="list.data" stripe v-loading="loading" header-row-class-name="head_color" tooltip-effect="dark"
            style="width: 99.8%" @selection-change="handleSelectionChange">
          <el-table-column type="selection" class="tc" width="35"></el-table-column>
          <el-table-column label="排序" sortable :sort-method="sorta" align="center" width="80">
            <template slot-scope="scope">
              <div>
                <el-input @change="sortNew(scope.$index, scope.row)" v-enterNumber v-model="scope.row.sort" autocomplete="off" size="small">
                </el-input>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="头像" min-width="80">
            <template slot-scope="scope">
              <div class="img_bor_tx">
                <img :src="$fnc.getImgUrl(scope.row.avatar)" alt />
              </div>
            </template>
          </el-table-column>

          <el-table-column label="讲师信息" min-width="150">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>标题：</span>
                  <span>{{ scope.row.title || "----" }}</span>
                </div>
                <div class="tutor_rate">
                  <span>评分：</span>
                  <el-rate v-model="scope.row.score" disabled show-score text-color="#ff9900" score-template="{value}"></el-rate>
                </div>
                <div>
                  <span>手机号：</span>
                  <span>{{ scope.row.tel }}</span>
                </div>
                <div>
                  <span>微信号：</span>
                  <span>{{ scope.row.wx }}</span>
                </div>
                <div>
                  <span>介绍：</span>
                  <span>{{ scope.row.industry }}</span>
                </div>
                <div>
                  <span>介绍2：</span>
                  <span>{{ scope.row.industry2 }}</span>
                </div>
                <div>
                  <span>标签：</span>
                  <span>{{ scope.row.label }}</span>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="讲师信息" min-width="150">
            <template slot-scope="scope">
              <div class="tab_div">

                <div>
                  <span>榜单：</span>
                  <span>{{ scope.row.list }}</span>
                </div>
                <div>
                  <span>热度：</span>
                  <span>{{ scope.row.hot }}</span>
                </div>
                <div>
                  <span>认证：</span>
                  <span>{{ scope.row.authentication }}</span>
                </div>
                <div>
                  <span>个人阅历：</span>
                  <span>{{ scope.row.experience }}</span>
                </div>
                <div>
                  <span>关注：</span>
                  <span>{{ scope.row.fans }}</span>
                </div>
                <div>
                  <span>粉丝：</span>
                  <span>{{ scope.row.consulting }}</span>
                </div>
                <div>
                  <span>获赞：</span>
                  <span>{{ scope.row.get_praise }}</span>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="讲师微信二维码" min-width="120">
            <template slot-scope="scope">
              <el-popover placement="right" title trigger="hover">
                <img :src="scope.row.wx_ewm" style="width: 500px" />
                <img slot="reference" :src="scope.row.wx_ewm" :alt="scope.row.wx_ewm" style="width: 100px" />
              </el-popover>
            </template>
          </el-table-column>
     
          <el-table-column label="是否显示" min-width="100">
            <template slot-scope="scope">
              <el-switch class="zdySwith" :width="82" v-model="scope.row.show" active-color="#1aad19" inactive-color="#ffffff" active-text="on"
                  inactive-text="off" active-value="1" @change="handleSwitch($event,scope.row)" inactive-value="0"></el-switch>
            </template>
          </el-table-column>
          <el-table-column label="时间信息" min-width="220">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>添加时间：</span>
                  <span>{{scope.row.created_time | getTimeFormat}}</span>
                </div>
                <div>
                  <span>修改时间：</span>
                  <span>{{scope.row.update_time | getTimeFormat}}</span>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="操作" min-width="120">
            <template slot-scope="scope">
              <el-row class="myblank">
                <el-button :loading="$store.state.isLoading" size="mini" @click="editbtn(scope.row)" type="primary">编辑</el-button>
                <el-button :loading="$store.state.isLoading" size="mini" @click="gotocase(scope.row)" type="primary">服务案例管理</el-button>
                <el-button :loading="$store.state.isLoading" size="mini" @click="gotocomment(scope.row)" type="primary">讲师评论管理</el-button>
                <el-button :loading="$store.state.isLoading" size="mini" type="danger" @click="deletebtn( scope.row.id)">删除</el-button>
              </el-row>
            </template>
          </el-table-column>
        </el-table>
      </template>

    </tableComponents>

    <el-dialog :close-on-click-modal="false" title="编辑" class="tl size_13" width="800px" :visible.sync="dialogFormVisible">
      <el-form :model="edit_form" ref="form" label-width="120px">

        <el-form-item label="标题：">
          <el-col :span="18">
            <el-input type="text" :rows="6" clearable placeholder="请输入标题" v-model="edit_form.title" autocomplete="off">
            </el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="头像" prop="username">
          <el-col :span="18" class="tl">
            <el-input v-model="edit_form.avatar" autocomplete="off" clearable class="mar_bottom_5" disabled></el-input>
            <uploadpic :piclink="edit_form.avatar" :width="150" :height="150" :real_width="150" :real_height="150" :is_more="false"
                @send_pic="onSuccess">
            </uploadpic>
          </el-col>
        </el-form-item>
        <el-form-item label="评分：">
          <el-col :span="18" style="height:40px;display:flex;align-items:center">
            <el-rate v-model="edit_form.score" show-score text-color="#ff9900" score-template="{value}"></el-rate>
          </el-col>
        </el-form-item>

        <el-form-item label="手机号：">
          <el-col :span="18">
            <el-input type="text" :rows="6" clearable placeholder="请输入手机号" v-model="edit_form.tel" autocomplete="off">
            </el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="微信号：">
          <el-col :span="18">
            <el-input type="text" :rows="6" clearable placeholder="请输入微信号" v-model="edit_form.wx" autocomplete="off">
            </el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="微信二维码" prop="username">
          <el-col :span="18" class="tl">
            <el-input v-model="edit_form.wx_ewm" autocomplete="off" clearable class="mar_bottom_5" disabled></el-input>
            <uploadpic :piclink="edit_form.wx_ewm" :width="150" :height="150" :real_width="150" :real_height="150" :is_more="false"
                @send_pic="onSuccess2">
            </uploadpic>
          </el-col>
        </el-form-item>
        <el-form-item label="介绍：">
          <el-col :span="18">
            <el-input type="text" :rows="6" clearable placeholder="请输入介绍" v-model="edit_form.industry" autocomplete="off">
            </el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="介绍2：">
          <el-col :span="18">
            <el-input type="text" :rows="6" clearable placeholder="请输入介绍2" v-model="edit_form.industry2" autocomplete="off">
            </el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="标签：">
          <el-col :span="18">
            <el-input type="text" :rows="6" clearable placeholder="请输入标签" v-model="edit_form.label" autocomplete="off">
              <span slot="append">用@隔开</span>
            </el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="榜单：">
          <el-col :span="18">
            <el-input type="text" :rows="6" clearable placeholder="请输入榜单" v-model="edit_form.list" autocomplete="off">
            </el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="热度：">
          <el-col :span="18">
            <el-input type="text" :rows="6" clearable placeholder="请输入热度" v-model="edit_form.hot" autocomplete="off">
            </el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="认证：">
          <el-col :span="18">
            <el-input type="text" :rows="6" clearable placeholder="请输入认证" v-model="edit_form.authentication" autocomplete="off">
            </el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="个人阅历：">
          <el-col :span="18">
            <el-input type="textarea" :rows="6" clearable placeholder="请输入个人阅历" v-model="edit_form.experience" autocomplete="off">
            </el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="关注：">
          <el-col :span="18">
            <el-input type="text" :rows="6" clearable placeholder="请输入关注" v-model="edit_form.fans" autocomplete="off">
            </el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="粉丝：">
          <el-col :span="18">
            <el-input type="text" :rows="6" clearable placeholder="请输入粉丝" v-model="edit_form.consulting" autocomplete="off">
            </el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="获赞：">
          <el-col :span="18">
            <el-input type="text" :rows="6" clearable placeholder="请输入获赞" v-model="edit_form.get_praise" autocomplete="off">
            </el-input>
          </el-col>
        </el-form-item>

        <el-form-item class="tc">
          <el-button :loading="$store.state.isLoading" type="primary" @click="editlive(edit_form)">编 辑</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <keep-alive>
      <component :is="current" :show="shows" :isAll="false" showType="list" @sendShop="getSend" @isshow="getShow"></component>
    </keep-alive>
  </div>
</template>
<script>
import xzuser from "@/components/currency/xz_user.vue";
import { dz_tutor_list } from "@/assets/js/searchData/searchData"; //引入搜索的数据
import cityCascader from "@/components/currency/cityCascader/cityCascader";
import uploadpic from "@/components/page/pic/up_pic";
export default {
  name: "huobi_strategy",
  data () {
    return {
      plad: "",
      userSearchData: dz_tutor_list,
      current: "",
      shows: false,
      is_edit: false,
      dialogDetailVisible: false,
      dialogFormVisible: false,
      edit_form: {
        avatar: ""
      },
      loading: false,
      list: [],
      allPage: 0,
      allNum: 0,
      pageSize: 10,
      currentPage: 1,
      searchAll: {},
      row: {},
      multipleSelection: [],
      showCity: true
    };
  },
  components: {
    xzuser,
    cityCascader,
    uploadpic
  },
  methods: {
    gotocomment (item) {
      var url = `/index/page/tutor_comment?id=${item.id}&name=${item.title}`;
      this.$store.commit("addbreadcrumbs", {
        title: item.title + "【评论列表】",
        url: url
      });
      this.$router.push(url);
    },
    gotocase (item) {
      var url = `/index/page/tutor_case?id=${item.id}&name=${item.title}`;
      this.$store.commit("addbreadcrumbs", {
        title: item.title + "【服务案例】",
        url: url
      });
      this.$router.push(url);
    },
    sorta (a, b) {
      return b - a;
    },
    sortNew (index, row) {
      var params = {};
      params = row;
      params.id = row.id;
      params.sort = row.sort;
      this.$api.getDz.edit_wishcate(params).then(res => {
        if (res.data.code == 200 && res.data.result) {
          return;
        } else {
          this.$fnc.alertError(res.data.code_desc, res.data.result); //失败弹出框
        }
      });
    },
    handleSwitch (val, item) {
      //审核
      var params = {};
      params = item || {};
      val == true ? (params["show"] = 1) : (params["show"] = 0);
      this.$api.getDz.edit_tutor_list(params).then(res => {
        //this.getNewsAll();
        if (res.data.code == 200) {
          this.$swal("修改成功！", res.data.result, "success");
          this.getNewsAll(this.searchAll);
        } else {
          this.$swal("修改失败！", res.data.result, "success");
          this.getNewsAll(this.searchAll);
        }
      });
    },

    onSuccess2 (pic) {
      this.$set(this.edit_form, 'wx_ewm', pic)
    },
    onSuccess (pic) {
      this.$set(this.edit_form, 'avatar', pic)
    },
    handleChange (value) {
      if (value) {
        for (var i = 0; i < value.length; i++) {
          if (i == 0) this.edit_form.province = value[i];
          if (i == 1) this.edit_form.city = value[i];
          if (i == 2) this.edit_form.area = value[i];
          if (i == 3) this.edit_form.town = value[i];
        }
      }
    },
    getShow (val) {
      this.shows = val;
    },
    getSend (row) {
      if (this.current == 'xzuser') {
        this.edit_form.username = row.username;
        this.edit_form.uid = row.id;
      } else {
        this.edit_form.car_brand_cn = row.name;
        this.edit_form.car_brand_id = row.id;
      }
    },
    xzshop (str) {
      this.current = str;
      this.shows = true;
    },
    handleSelectionChange (val) {
      this.multipleSelection = val;
    },
    deleteAll () {
      //批量删除
      var str = "";
      if (this.multipleSelection.length <= 0) {
        this.$message.error("未选择批量删除");
      } else {
        for (var i in this.multipleSelection) {
          str += this.multipleSelection[i].id + "@";
        }
        str = str.slice(0, -1);
        this.$swal({
          title: "您确定要删除这些信息吗",
          text: "删除后将无法恢复，请谨慎操作！",
          type: "warning",
          showCancelButton: true,
          confirmButtonColor: "#DD6B55",
          confirmButtonText: "是的，我要删除",
          cancelButtonText: "容我三思"
        }).then(willDelete => {
          if (willDelete.value) {
            this.$api.getDz.del_tutor_list({ id_str: str }).then(res => {
              if (res.data.code == 200) {
                this.$swal("删除成功！", res.data.result, "success");
                this.getNewsAll(this.searchAll);
              } else {
                this.$swal("删除失败！", res.data.result, "success");
                this.getNewsAll(this.searchAll);
              }
            });
          }
        });
      }
    },
    deletebtn (id) {
      //删除
      this.$swal({
        title: "您确定要删除这些信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思"
      }).then(willDelete => {
        if (willDelete.value) {
          this.$api.getDz.del_tutor_list({ id: id }).then(res => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", res.data.result, "success");
              this.getNewsAll(this.searchAll);
            } else {
              this.$swal("删除失败！", res.data.result, "success");
              this.getNewsAll(this.searchAll);
            }
          });
        }
      });
    },
    add_data () {
      this.edit_form = {
      };

      this.is_edit = false;
      this.dialogFormVisible = true;
    },

    getIs (val, row) {
      this.is_edit = true;
      var params = {};
      params = row;
      params.id = row.id;
      params.show = val;

      this.editlive(params);
    },

    editlive (item) {
      var params = {};
      params = item;
      if (this.is_edit == false) {
        this.$api.getDz.add_tutor_list(params).then(res => {
          if (res.data.code == 200) {
            this.dialogFormVisible = false;
            this.$fnc.alertSuccess(res.data.result);
            this.getNewsAll(this.searchAll);
          } else {
            this.$fnc.alertError(res.data.result);
          }
        });
      } else {
        params.id = item.id;
        this.$api.getDz.edit_tutor_list(params).then(res => {
          if (res.data.code == 200) {
            this.dialogFormVisible = false;
            this.$fnc.alertSuccess(res.data.result);
            this.getNewsAll(this.searchAll);
          } else {
            this.$fnc.alertError(res.data.result);
          }
        });
      }
    },

    editbtn (item) {
      this.is_edit = true;
      this.edit_form = JSON.parse(JSON.stringify(item));
      this.dialogFormVisible = true;
    },

    receive_search (obj) {
      this.searchAll = obj;
      this.getNewsAll(obj);
    },
    getNewsAll (data) {
      this.loading = true;
      var params = {};
      data = data || {};
      params = data;
      this.$api.getDz.get_tutor_list(params).then(res => {
        if (res.data.code == 200) {

          this.list = res.data.result;
          this.list.data.forEach((item, i) => {
            item.score = Number(item.score);
          })
        }
        this.loading = false;
      });
    },
    handleSizeChange (val) {
      var params = this.searchAll;
      params.page = "";
      params.page_size = val;
      this.getNewsAll(params);
      this.pageSize = val;
    },
    handleCurrentChange (val) {
      this.currentPage = val;
      var params = this.searchAll;
      params.page = val;
      params.page_size = this.pageSize;
      this.getNewsAll(params);
    },

    reload () {
      this.getNewsAll(this.searchAll);
    }
  },
  beforeCreate () { },
  created () {
    this.getNewsAll();
  },
  computed: {}
};
</script>

<style lang="less" scoped>
.myblank button {
  margin: 5px 5px 0 0;
}
.partitem {
  font-size: 14px;
  display: flex;
  flex-wrap: nowrap;
  justify-content: flex-start;
  align-items: center;
  margin-bottom: 15px;
  > p {
    font-weight: bold;
  }
}
</style>
